#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int main()
{
  int pipefd[2]={2};
  int ret=pipe(pipefd);
  if(ret<0)
  {
    perror("pipe errror");
    return -1;
  }

  pid_t id=fork();
  if(id<0)
  {
    perror("fork error");
    return -1;
  }else if(id==0)
  {//child

    //sleep(4);

    char *data=" 今天天气很好\n ";
//写入数据
    write(pipefd[1],data,strlen(data));

  }else 
  {//parent
    char buf[1024]={0};

//读取数据
   sleep(4);

    read(pipefd[0],buf,1023);
    printf("read buf :%s",buf);
  }

  return 0;
}
